package com.zxj.friend.controller.file;

import com.zxj.common.core.contains.HttpConstants;
import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.common.file.domain.OSSResult;
import com.zxj.friend.aspect.CheckUserStatus;
import com.zxj.friend.service.file.IFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Tag(name = "文件上传", description = "文件上传API")
public class FileController extends BaseController {

    @Autowired
    private IFileService sysFileService;

    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @CheckUserStatus // 检查用户状态, 进行拉黑限制
    public R<OSSResult> upload(@RequestBody MultipartFile file) {
        return R.ok(sysFileService.upload(file));
    }
}
